package com.young.shop.controller;

import com.young.shop.pojo.entity.User;
import com.young.shop.service.UserService;
import com.young.shop.service.impl.UserServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/ChangeEmail")
public class ChangeEmailController extends BaseController {
    private UserService userService=new UserServiceImple();
    @Override
    protected void doGet(HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        //获取要修改的邮箱账号 输入的验证码
        String email = req.getParameter("email");
        String code = req.getParameter("code");
        System.out.println(email);
        System.out.println(code);
        //得到登录的用户信息
        User user =(User) req.getSession().getAttribute("client");
        //校验邮箱是否存在、是否已经存在
        //判断验证码是否相同
        try{
            User dbUser = userService.verifyEmail(user , email , code);
            writerSucccessBaseRespVoToResponse(resp,dbUser);
        }catch (RuntimeException e){
            writerFailedBaseRespVoToResponse(resp,e);
        }
        //修改数据库对应的邮箱
    }
}
